using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
using Utility;
using System.Drawing;
public partial class admin_A_TinhTrang_phieu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddata();
        }
        else
        {
            loaddata1();
        }
    }
    private void loaddata()
    {
       

        Criteria cri = new Criteria();


        if (txttentinhtrangsp.Text != "")
        {
            cri.add(Condition.AND, TinhTrang_PhieuColumns.TenTinhTrang, Condition.LIKE, txttentinhtrangsp.Text);
        }
        
        if (txtmatinhtrangsp.Text != "")
        {
            cri.add(Condition.AND, TinhTrang_PhieuColumns.MaTinhTrang_Phieu, Condition.EQUAL, int.Parse(txtmatinhtrangsp.Text));
        }
        
        int total = 0;
        TinhTrang_PhieuCollection ttsp = TinhTrang_Phieu_BUS.Get(cri.Criter, 0, 0, TinhTrang_PhieuColumns.MaTinhTrang_Phieu.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = ttsp;
        Repeater1.DataBind();



    }
    private void loaddata1()
    {



        Criteria cri = new Criteria();


        //if (txttentinhtrangsp.Text != "")
        //{
        //    cri.add(Condition.AND, TinhTrang_PhieuColumns.TenTinhTrang, Condition.LIKE, txttentinhtrangsp.Text);
        //}

        //if (txtmatinhtrangsp.Text != "")
        //{
        //    cri.add(Condition.AND, TinhTrang_PhieuColumns.MaTinhTrang_Phieu, Condition.EQUAL, int.Parse(txtmatinhtrangsp.Text));
        //}

        int total = 0;
        TinhTrang_PhieuCollection ttsp = TinhTrang_Phieu_BUS.Get(cri.Criter, 0, 0, TinhTrang_PhieuColumns.MaTinhTrang_Phieu.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = ttsp;
        Repeater1.DataBind();



    }
    
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            TinhTrang_Phieu_DTO lh = (TinhTrang_Phieu_DTO)e.Item.DataItem;
            HyperLink hplsua = (HyperLink)e.Item.FindControl("hplsua");
            hplsua.NavigateUrl = "~/admin/A_tinhtrang_phieu_update.aspx?matinhtrang=" + lh.MaTinhTrang_Phieu.ToString();

        }
    }
    public bool IsNumeric(string val)
    {
        double result;
        return double.TryParse(val, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.CurrentInfo, out result);
    }
    protected void bttimkiem_Click(object sender, EventArgs e)
    {
        
        string maloai = txtmatinhtrangsp.Text;

        if (IsNumeric(maloai) == false)
        {
            txtmatinhtrangsp.ForeColor = Color.Red;
           // loaddata();
            return;
        }
        else
        {

            txtmatinhtrangsp.ForeColor = Color.Black;
            loaddata();

        }
            

       
           
       
    }
}
